package com.snail.clouds.framework.dto;

import com.snail.clouds.framework.entity.CloudAccount;
import lombok.Data;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;

/**
 * 云存储账户信息DTO
 */
@Data
@Accessors(chain = true)
public class CloudAccountDTO {
    /**
     * 账号ID
     */
    private Long id;
    
    /**
     * 所属用户ID
     */
    private Long userId;
    
    /**
     * 云盘类型(tianyi/alibaba/baidu等)
     */
    private String cloudType;
    
    /**
     * 云盘账号
     */
    private String account;
    
    /**
     * 账号状态(active/inactive/error)
     */
    private String status;
    
    /**
     * 账号信息JSON
     */
    private String accountInfo;
    
    /**
     * 总存储空间(字节)
     */
    private Long totalStorage;
    
    /**
     * 已用存储空间(字节)
     */
    private Long usedStorage;
    
    /**
     * 创建时间
     */
    private LocalDateTime createdAt;
    
    /**
     * 更新时间
     */
    private LocalDateTime updatedAt;
    
    /**
     * 将CloudAccount实体转换为CloudAccountDTO
     * @param account 云存储账户实体
     * @return 云存储账户信息DTO
     */
    public static CloudAccountDTO convert(CloudAccount account) {
        if (account == null) {
            return null;
        }
        
        CloudAccountDTO dto = new CloudAccountDTO();
        dto.setId(account.getId());
        dto.setUserId(account.getUserId());
        dto.setCloudType(account.getCloudType());
        dto.setAccount(account.getAccount());
        dto.setStatus(account.getStatus());
        dto.setAccountInfo(account.getAccountInfo());
        dto.setTotalStorage(account.getTotalStorage());
        dto.setUsedStorage(account.getUsedStorage());
        dto.setCreatedAt(account.getCreatedAt());
        dto.setUpdatedAt(account.getUpdatedAt());
        return dto;
    }
    
    /**
     * 将CloudAccountDTO转换为CloudAccount实体
     * @param dto 云存储账户信息DTO
     * @return 云存储账户实体
     */
    public static CloudAccount convertToEntity(CloudAccountDTO dto) {
        if (dto == null) {
            return null;
        }
        
        CloudAccount account = new CloudAccount();
        account.setId(dto.getId());
        account.setUserId(dto.getUserId());
        account.setCloudType(dto.getCloudType());
        account.setAccount(dto.getAccount());
        account.setStatus(dto.getStatus());
        account.setAccountInfo(dto.getAccountInfo());
        account.setTotalStorage(dto.getTotalStorage());
        account.setUsedStorage(dto.getUsedStorage());
        account.setCreatedAt(dto.getCreatedAt());
        account.setUpdatedAt(dto.getUpdatedAt());
        return account;
    }
}